<?php

header("Access-Control-Allow-Origin: *");  // 允许所有域访问
header("Content-Type: application/json; charset=UTF-8");

// 数据库连接配置
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "dm_store";

// 创建连接
$conn = new mysqli($servername, $username, $password, $dbname);

// 检查连接
if ($conn->connect_error) {
    die("连接失败: " . $conn->connect_error);
}

// 查询数据
$sql = "SELECT * FROM fenlei";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // 输出每行数据
    $rows = [];
    while($row = $result->fetch_assoc()) {
        $rows[] = $row;
    }
    echo json_encode($rows);  // 返回 JSON 格式的数据
} else {
    echo "0 results";
}

$conn->close();
?>
